structures in C

빵꾸난 지식들

아래의 예시는 비트빌드를 사용해 임의로 정수 멤버의 크기를 4바이트에서 3바이트로 줄인 것을 볼 수 있다.

struct str1 {
	int a;
	char c;
};
struct str2 {
	int a : 24; // size of 'a' is 3 bytes = 24 bits
	char c;
};

sizeof(struct str1); // 4 + 1이상 가장 작은 4의 배수인 8
sizeof(struct str2); // 3 + 1이상 가장 작은 4의 배수인 4